<?php
    $conn = new mysqli('localhost', 'root', 'root', 'sy2202');

    if ($conn -> connect_error) {
        die('连接错误');
    }

    $username = $_POST['username'];
    $password = $_POST['password'];

    $sql = "SELECT * FROM `user` WHERE `username`='$username' AND `password`='$password'";

    $res = $conn -> query($sql);

    $obj = mysqli_fetch_assoc($res);

    if ($obj) {
        echo json_encode(array(
            "msg" => "登录成功",
            "state" => true,
            "username" => $username
        ));
    } else {
        echo json_encode(array(
            "msg" => "账户名或者密码错误",
            "state" => false
        ));
    }
?>